import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { SupplierTypeDto } from '../../proxy/joy/erp/basic-archives/suppliers';

@Component({
  selector: 'lib-supplier-type-ref-entity',
  templateUrl: './supplier-type-ref-entity.component.html',
})
export class SupplierTypeRefEntityComponent implements OnInit {
  @Input() model: SupplierTypeDto;

  validateForm: FormGroup;
  
  constructor(public fb: FormBuilder, public modalRef: NzModalRef) {}

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      displayName: [this.model?.displayName, [Validators.required, Validators.maxLength(200)]],
    });
  }

  cancelForm() {
    this.modalRef.close(null);
  }

  submitForm() {
    if (!this.validateForm.valid) return;
    this.modalRef.close({
      ...this.model,
      ...this.validateForm.value,
    });
  }
} 